
data$forcing = as.integer(as.Date("1990-11-04"))- as.integer(as.Date(data$dob))
data$Cutoff08 = ifelse(data$forcing >= 0, 1, 0)



################# DV: Vote 2016 ########################

ivmod1_white = state.cace.estimator.order(order=p, lag="no", data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)
ivmod1_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                             downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod1_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                            downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod2_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod3_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)
ivmod3_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod4_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)
ivmod4_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod5_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod_rep_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)



ivmod6_white = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                            downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                            downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic = state.cace.estimator.order(order=p, lag="no",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                               downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)




#rm(data)
filename = paste0("results_", state, "_specification_", p,"nolag.Rdata")
save.image(paste0("results/", filename))
rm(list=ls(pattern = "mod"))


#### lag
################# DV: Vote 2016 ########################

ivmod1_white = state.cace.estimator.order(order=p, lag="yes", data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)
ivmod1_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)
ivmod1_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)


ivmod2_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)
ivmod2_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)
ivmod2_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod3_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)
ivmod3_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)
ivmod3_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod4_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)
ivmod4_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)
ivmod4_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod5_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "democrat_white", downstream_lag = "lagdem_white", bandwidth = 365, state.abbrev=NULL)
ivmod5_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "democrat_black", downstream_lag = "lagdem_black", bandwidth = 365, state.abbrev=NULL)
ivmod5_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "democrat_hispanic", downstream_lag = "lagdem_hispanic", bandwidth = 365, state.abbrev=NULL)

ivmod_rep_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                             downstream_voted = "republican_white", downstream_lag = "lagrep_white", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                             downstream_voted = "republican_black", downstream_lag = "lagrep_black", bandwidth = 365, state.abbrev=NULL)
ivmod_rep_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                                downstream_voted = "republican_hispanic", downstream_lag = "lagrep_hispanic", bandwidth = 365, state.abbrev=NULL)



ivmod6_white = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_white", 
                                          downstream_voted = "white", downstream_lag = "lagregistered_white", bandwidth = 365, state.abbrev=NULL)
ivmod6_black = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_black", 
                                          downstream_voted = "black", downstream_lag = "lagregistered_black", bandwidth = 365, state.abbrev=NULL)
ivmod6_hispanic = state.cace.estimator.order(order=p, lag="yes",data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote.gen2008_hispanic", 
                                             downstream_voted = "hispanic", downstream_lag = "lagregistered_hispanic", bandwidth = 365, state.abbrev=NULL)




rm(data)
filename = paste0("results_", state, "_specification_", p,"lag.Rdata")
save.image(paste0("results/", filename))
rm(list=ls(pattern = "mod"))

